package org.example.j2024_11_4;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttribute;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/session")
public class SessionController {

    @RequestMapping("/set")
    public String set(HttpServletRequest request){
        HttpSession session = request.getSession();
        session.setAttribute("name","zhansan");
        session.setAttribute("id",1);
        return "设置session成功";
    }

    @RequestMapping("/s1")
    public String s1(HttpServletRequest request){
        HttpSession session = request.getSession();
        return "name:"+session.getAttribute("name") + "id"+session.getAttribute("id");
    }

     @RequestMapping("/s2")
    public String s2(HttpSession session){
        return"name:"+session.getAttribute("name") + "id"+session.getAttribute("id");
     }

     @RequestMapping("/s3")
    public String s3(@SessionAttribute("name") String name){
     return name ;
     }

}
